﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class MasterPageDetail : System.Web.UI.MasterPage
{
    public int loaisanphamid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            LoadLoaiSanPham();
            //this.UserCP.loaisanpham = loaisanphamid;
            MasterPage m = this.Master as MasterPage;
            m.loaisanphamid = loaisanphamid;
            LoadDoiTac();
        }
    }

    private void LoadLoaiSanPham()
    {
        LoaiSanPhamDataSet lspds;
        if (loaisanphamid == 0)
        {
            lspds = new LoaiSanPhamHelper().LoadLoaiSanPhamGoc();
            lbLoaiSanPham.Text = "Danh mục hệ thống";
        }
        else
        {
            lspds = new LoaiSanPhamHelper().LoadLoaiSanPhamConMenu(loaisanphamid);
            lbLoaiSanPham.Text = (new LoaiSanPhamHelper().LoadLoaiSanPham(lspds.LoaiSanPham[0].LoaiSanPhamChaID)).LoaiSanPham[0].TenLoaiSanPham;
        }

        repListCha.DataSource = lspds;
        repListCha.DataBind();
    }

    protected void repListCha_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            LoaiSanPhamHelper lspHP = new LoaiSanPhamHelper();
            Repeater repCon = ((Repeater)e.Item.FindControl("repCon"));
            repCon.DataSource = (lspHP.LoadLoaiSanPhamCon(Convert.ToInt32((((DataRowView)e.Item.DataItem)["LoaiSanPhamID"]))));
            repCon.DataBind();
        }
    }

    private void LoadDoiTac()
    {
        DoiTacDataSet bnDS = new DoiTacHelper().LoadDoiTac();
       repDoiTac.DataSource = bnDS;
       repDoiTac.DataBind();

        
    }

}
